<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title></title>
    <meta charset="UTF-8">
    <meta name="renderer" content="ie-comp">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/bootstrap-responsive.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/style.css">
    
<link type="text/css" href="__PUBLIC__/Admin/css/b5m-plugin.css" rel="stylesheet">
<link type="text/css" href="__PUBLIC__/Admin/css/b5m.css" rel="stylesheet">
 <style type="text/css">
        body {
            padding-bottom: 40px;
            font-size:16px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
       
        #bg{width:100%;height:100%;top:0px;left:0px;position:absolute;filter: Alpha(opacity=50);opacity:0; background:#000000; display:none;}
       #popbox{position:absolute;width:400px; height:400px; left:55%; top:60%; margin:-200px 0 0 -200px; display:none; background:#fff;}
    </style>
 
</head>
<body>
	
   <?php if(session('roleid')!=5) {?> 
    <div class="form-inline definewidth m20">
          
  	可分配<span id="total" style="color:blue"><?php if($count!="") echo $count;else echo $count1?></span>条资源：

  		<select name="" id="userid">
            <option selected="selected" value="-1">分配</option>
            <volist name='user' id='r'>
            <option value="{$r.userid}">{$r.username}</option>
            </volist>
      </select>


  		<input id="count" onkeydown="if(event.keyCode==13)distribute()" type="text">
    <button type="button" class="btn btn-primary" onclick="distribute()">分配</button>
    <br>

    </div>
   <?php }?>
   <?php if(session('roleid')==0) {?> 
    <div class="form-inline definewidth m20">
	删除资源：<select name="statusId" id="uploadsid">
    <option value="-1" selected="selected">资源使用状态</option>
    <option value="1">申请未通过</option>
    <option value="2">已通过</option>
    <option value="3">意向客户</option>
    <option value="4">已入金</option>
    <option value="5">非微信号码</option>
	<input class="btn btn-primary" value="删除" onclick="deleteResouece()" type="button">

</div>

<div class="form-inline definewidth m20">
	资源去重：<input value="点击去除重复数据" onclick="deleteRepeat()" class="btn btn-primary" type="button">
</div>

<?php }?>

  <?php if(session('roleid')==5){?>
  <div style="margin-top: 20px;">
   <span style="margin-left:30px;">未使用资源：<?php echo $pagecount?>条</span>
 
	<table class="table table-bordered table-hover definewidth m10">
  		<tbody>
  		      <tr align="center">
  		          <td>资源号码</td>
  		          <td>分配时间</td>
  		          <td width="440px">修改状态下拉列表</td>
  		          <td>资源备注</td>
                <td>操作</td>
  		       </tr>
  			<volist name='resourceInfo' id='r'>
  			   <tr>
  				<td><span id="pnumber{$r.id}">{$r.pnumber}</span>
  				    <!-- <input id="BTNcOPY_{$r.id}" class="btn btn-primary" value="复制" onclick="copy2Clip({$r.id})" type="button"> -->
  				</td>
  				<td>
  				    {$r.updatetime|date='Y-m-d H:i',###}
  				 </td>
  				<td>
  				   <select id="{$r.id}" name="sid" style="float:left" onchange="test({$r.id})">
  					<option selected="selected" value="-1">请选择</option>
  					<option value="1">申请未通过</option>
  					<option value="2">已通过</option>
  					<option value="3">意向客户</option>
  					<option value="4">已入金</option>
  					<option value="5">非微信号码</option>
  				  </select>
  				<div id="childselect{$r.id}" style="display:none;float:left">
  					<select name="sid" id="myresourceid{$r.id}">
  						<option selected="selected" value="-1">请选择</option>
  						<option value="6">A类意向客户</option>
  						<option value="7">B类意向客户</option>
  						<option value="8">C类意向客户</option>
  						<option value="9">D类意向客户</option>
  					</select>
  				</div>
  				</td>
  				<td>
  				    <input id="wechatname{$r.id}" type="text">
  				</td>
  				<td>
  				   <a href="javascript:update({$r.id})" style="text-decoration: NONE" class="btn btn-primary">提交</a>
  				</td>
  				</tr>
  			</volist>
         </tbody>
         </table>
         </div>
          <div class="inline  page" style="text-align: center;">
            {$pagecount} 条记录 {$page}/{$resPage}页 
  　         <a style="margin-right: -10px;" href="javascript:upPage({$page})">上一页</a>
  　         <span style="color:red">{$page}</span>
   　　      <a style="margin-left: -30px;" href="javascript:nextPage({$page},{$resPage})">下一页</a>
             &nbsp;&nbsp;&nbsp;跳转到第<input id="toPage" style="width:30px;height:20px;padding-top: 4px;" type="text">页
            <a href="javascript:toGoPage()">跳转</a>
    　  </div> 
   <?php } ?> 

       <a href="#" onclick="pupopen()"></a>
       <div id="bg"></div>
       <div id="popbox">
          <img src="__PUBLIC__/Admin/images/loading.gif">
          <a href="#"  onclick="pupclose()"></a>
      </div>
</body>
<script type="text/javascript" src="__PUBLIC__/Admin/js/jquery.js"></script>
    <!--<script type="text/javascript" src="Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="__PUBLIC__/Admin/js/bootstrap.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/js/ckform.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/js/jquery-1.js"></script>
    <script type="text/javascript">
     function pupopen(){
          document.getElementById("bg").style.display="block";
          document.getElementById("popbox").style.display="block" ; 
    }

    function pupclose(){
          document.getElementById("bg").style.display="none";
          document.getElementById("popbox").style.display="none" ;  
    }
</script>
    <script type="text/javascript">
      $(function(){
        $("#uploadsid").val(-1);
      });
    </script>
    <script type="text/javascript">
      function distribute(){
      var userid = $("#userid").val();
      var count = $("#count").val();
      var ziyuan = $("#total").html();
      if(count > ziyuan){
        alert('分配资源数大于现有资源数');
        return ;
      }
      if(userid==-1){
        alert("请选择分配资源对象");
        $("#userid").focus();
        return ;
      }
      if(count==""){
        alert("请输入分配资源数量");
        return ;
      }
      
      var run = confirm("是否分配资源?");
      if(run){
            pupopen();
            $.ajax({
                    type: 'POST',
                    url: "{:U('Zygl/allocate')}",
                    data: {userid:userid,count:count},
                    dataType : "json", 
                    success: function(data) {
                      pupclose();
                      if(data.ok==1){ 
                        alert("资源分配成功");
                        window.location.href="{:U('Zygl/zygl')}";
                      } 
                      if(data.ok==2){
                        alert("资源分配失败");
                      }
                    }
            }); 
      }
    }

    function deleteResouece(){
      var sid = $("#uploadsid").val();
      if(sid==-1){
        alert("请选择要删除的资源类型");
        return ;
      }
      var run = confirm("是否删除资源?");
      if(run){
        pupopen();
        $.post("{:U('Zygl/delete')}",{"statusId":sid},function(data){
          pupclose();
          var flag = data.ok;
          if(flag==0){
            alert('没有该资源');
            return false;
          }
          if(flag==1){
            alert("删除成功!");
            window.location.reload();
          }
          if(flag==2){
            alert("删除失败!");
          }
        },"JSON");      
      }
    }
  

  </script>

<script type="text/javascript">
  function test(obj){
    var statusid = $("#"+obj+"").val();
    if(statusid==3){
      $("#childselect"+obj+"").show();
        
    }else{
      $("#childselect"+obj+"").hide();
    }
  }
  function deleteRepeat(){
     pupopen();
     $.ajax({
              type: 'POST',
              url: "{:U('Zygl/quchong')}",
              data: {},
              dataType : "json", 
              success: function(data) {
                pupclose();
                  if(data.ok==1) {
                    alert("数据去重成功");
                    window.location.reload();
                  }
                  if(data.ok==0){
                    alert('没有重复资源');
                  }
                  if(data.ok==2){
                    alert('数据去重失败，重复数据太多！');
                  }  
                }
          }) 
  }
</script>
<script type="text/javascript">


function update(obj){
      var resourceid = obj; 
      var statusid=$("#"+obj+"").val();
      if(statusid==3){
        statusid=$("#myresourceid"+obj+"").val();
      }
      var wechatname = $("#wechatname"+obj+"").val();
      if(statusid!=6){
        if(wechatname==""){
        alert("请输入资源备注");
        return ;
        } 
      }
      if(statusid==-1){
        alert("请选择资源状态");
        return ;
      }

      var run = confirm("是否更新资源?");
      if(run){
          $.ajax({
              type: 'POST',
              url: "{:U('Zygl/update')}",
              data: {"resourceId":resourceid,"statusId":statusid,"wechatName":wechatname},
              dataType : "json", 
              success: function(data) {
                 if(data.ok==1){
                     alert("修改成功");
                     window.location.reload();
                     var statusid=$("#"+obj+"").val(-1);
                     var wechatname = $("#wechatname"+obj+"").val("");
                  }
                  if(data.ok==2){
                     alert("修改失败");
                     window.location.reload();
                     var statusid=$("#"+obj+"").val(-1);
                     var wechatname = $("#wechatname"+obj+"").val("");
                  }
              }
          }) 
      }
    }

    function upPage(page){
    if(page==1){
      alert('已经是第一页了');
    }else{
      page--;
    }
    window.location.href="zygl?page="+page;
       
  }
  function nextPage(page,pa){

    if(page==pa){
      alert('已经是最后一页了');
    }else{
      page++;
    }
    window.location.href="zygl?page="+page;
       
  }
  function toGoPage(){
    var page = $('#toPage').val();
    if(isNaN(page)){
      alert('请输入数字');
      exit;
    }
    window.location.href="zygl?page="+page;
  }
</script>
<script src="__PUBLIC__/Admin/js/b5m.js" charset="utf-8" id="b5mmain" type="text/javascript"></script>
</html>